package com.zhugang.week02;

/**
 * @program algorithms
 * @description: sentinel
 * @author: chanzhugang
 * @create: 2022/04/19 08:33
 */
public class SentinelDemo {

    /**
     * 数组中查找key，返回key所在位置
     *
     * @param c
     * @param n
     * @param key
     * @return
     */
    public int find(char[] c, int n, char key) {
        // 边界条件处理
        if (c == null || n <= 0) {
            return -1;
        }
        int i = 0;
        while (i < n) {
            if (c[i] == key) {
                // 满足条件
                return i;
            }
            i++;
        }
        return -1;
    }
}